<template>
  <div class="gl_contentBox gl_heightFull">
    <div v-if="flag" class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :span="4">
          <p>搜索学员</p>
          <el-input v-model="Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Filter" size="mini" placeholder="学员姓名" clearable @change="getattentList()" />
        </el-col>
        <!-- <el-col :span="5.5">
          <p>考勤日期</p>
          <el-date-picker v-model="freeDay" type="daterange" range-separator="至" start-placeholder="请选择日期" end-placeholder="请选择日期" size="mini" value-format="yyyy-MM-dd" style="width:100%" />
        </el-col> -->
        <el-col :span="2.5">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="getattentList()">筛选</el-button>
        </el-col>
        <el-col :span="2.5">
          <el-button type="warning" style="margin-top:25px" size="mini" :loading="btnUpLoading" @click="exportstudent()">导出数据</el-button>
        </el-col>
      </el-row>
    </div>
    <div v-if="flag" style="margin-top:20px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column type="index" label="序号" align="center" width="100" />
        <el-table-column label="学员" prop="studentName" />
        <el-table-column label="证件号码" prop="idCardNumber" />
        <el-table-column label="销课数量" prop="courseCount" />
        <el-table-column label="剩余课时" prop="remainClassPeriod" />
        <el-table-column label="最晚到期时间" prop="effectiveDate">
          <template slot-scope="{ row }">
            <span v-if="row.effectiveDate">
              {{ row.effectiveDate | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <el-button type="text" size="mini" style="color:#1990FF" @click="attend(row.id)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Page"
        :page-size="Api_GET_ClubCheckInLogStudentCheckInInfoListQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { api_GET_DownLoadFileAddHeader } from '@/extend/api/file';
import { errorText } from '@/lib';
import { api_GET_ClubCheckInLogStudentCheckInInfoList } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubCheckInLogStudentCheckInInfoListQO } from '@/lib/form/hall/swaggerForm';
export default {
  data() {
    return {
      btnUpLoading: false,
      GetStudentInput: {},
      tableLoading: false,
      freeDay: [],
      totalPage: 0,
      currentPage: 1,
      Api_GET_ClubCheckInLogStudentCheckInInfoListQO: new Api_GET_ClubCheckInLogStudentCheckInInfoListQO(),
      paymentTime: [],
      flag: true,
      tableData: []
    };
  },
  watch: {
    freeDay: {
      immediate: true,
      deep: true,
      handler(val) {
        if (val && val.length !== 0) {
          this.changeProportion(val);
        }
      }
    }
  },
  created() {
    this.getattentList();
  },
  methods: {
    attend(id) {
      this.$router.push({ name: 'Attendancedet', 'query': { 'id': id }});
    },
    getattentList(page) {
      this.tableLoading = true;
      this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Page = page || 1;
      this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.SkipCount = (this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Page - 1) * this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.MaxResultCount;
      api_GET_ClubCheckInLogStudentCheckInInfoList(this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO).then(res => {
        console.log(res);
        this.tableData = res.items;
        this.totalPage = res.totalCount;
        this.tableLoading = false;
      }, error => {
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.MaxResultCount = MaxResultCount;
      this.getattentList();
    },
    pageIndexChange(currentPage) {
      this.getattentList(currentPage);
    },
    exportstudent() {
      this.GetStudentInput = {};
      this.btnUpLoading = true;
      if (this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Filter !== null) {
        this.GetStudentInput.Filter = this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Filter;
      } else {
        console.log(this.GetStudentInput);
        this.GetStudentInput.Filter = '';
      }
      this.GetStudentInput.Sorting = 'creationTime DESC';
      this.GetStudentInput.Page = this.Api_GET_ClubCheckInLogStudentCheckInInfoListQO.Page;
      this.GetStudentInput = JSON.stringify(this.GetStudentInput);
      var that = this;
      const tempUrl = `/api/excel`;
      const fileName = '考勤' + '.xlsx';
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, { reportName: 'Attendance', GetStudentCheckInInfoInput: this.GetStudentInput }, WEB_CONFIG.VUE_APP_SWAGGER_HALL_BASE).then(res => {
        this.btnUpLoading = false;
      }).catch(error => {
        this.btnUpLoading = false;
        this.GetStudentInput = {};
        errorText(error).then(function(text) {
          this.GetStudentInput = {};
          that.$message({ type: 'error', message: text });
        });
      });
    }
  }
};
</script>

<style>

</style>
